import Store from "../../store";
import editor from "../../global/editor";
import menuButton from "../menuButton";
// 设置格式列表的确认函数
const listConfirmFns = {
  automatic() {
    let d = editor.deepCopyFlowData(Store.flowdata);//取数据
    menuButton.updateFormat(d, "ct", 'General');
  },
  text() {
    let d = editor.deepCopyFlowData(Store.flowdata);//取数据
    menuButton.updateFormat(d, "ct", '@');
  },
  num() {
    const decimal = Number($('#numDecimal').val())
    let decStr = new Array(decimal).fill(0).join('')

    const separator = $('#numSepa').prop('checked')

    let d = editor.deepCopyFlowData(Store.flowdata);//取数据
    // _this.focus($menuButton, itemvalue);
    const itemvalue = `${separator ? '#,' : ''}##0${decimal === 0 ? '' : `.${decStr}`}`
    menuButton.updateFormat(d, "ct", itemvalue);

  },
  percent() {
    // 百分比
    const decimal = Number($('#percentNumDecimal').val())
    let decStr = new Array(decimal).fill(0).join('')

    let d = editor.deepCopyFlowData(Store.flowdata);//取数据

    const itemvalue = `#0${decimal === 0 ? '' : `.${decStr}`}%`
    menuButton.updateFormat(d, "ct", itemvalue);

  },
  sci() {
    // 科学计数
    const decimal = Number($('#sciNumDecimal').val())
    let decStr = new Array(decimal).fill(0).join('')

    let d = editor.deepCopyFlowData(Store.flowdata);//取数据

    const itemvalue = `0${decimal === 0 ? '' : `.${decStr}`}E+00`
    menuButton.updateFormat(d, "ct", itemvalue);

  },
  accounting() {
    // 会计计数
    // $(0.00)
    const decimal = Number($('#accountingNumDecimal').val())
    let decStr = new Array(decimal).fill(0).join('')

    const curDom = $('#accountingList').find('.accountingItem.curListItem')
    let str = '￥'
    if (curDom) {
      str = curDom.data('value')
    }

    let d = editor.deepCopyFlowData(Store.flowdata);//取数据
    const itemvalue = `${str}(0${decimal === 0 ? '' : `.${decStr}`})`
    menuButton.updateFormat(d, "ct", itemvalue);

  },
  currency() {
    // 货币计数

    // $ 0.00
    const decimal = Number($('#currencyNumDecimal').val())
    let decStr = new Array(decimal).fill(0).join('')

    const curDom = $('#currencyList').find('.currencyItem.curListItem')
    let str = '￥'
    if (curDom) {
      str = curDom.data('value')
    }

    let d = editor.deepCopyFlowData(Store.flowdata);//取数据
    const itemvalue = `${str}0${decimal === 0 ? '' : `.${decStr}`}`
    menuButton.updateFormat(d, "ct", itemvalue);


  },
  date() {
    // 日期
    const curDom = $('#fmtDateList').find('.curListItem')
    debugger
    if (curDom) {
      let d = editor.deepCopyFlowData(Store.flowdata);//取数据
      let fa = decodeURIComponent(curDom.data('value'))
      menuButton.updateFormat(d, "ct", fa);
    }
  },
  time() {
    // 时间
    const curDom = $('#fmtDateList').find('.curListItem')
    if (curDom) {
      let d = editor.deepCopyFlowData(Store.flowdata);//取数据
      const fa = decodeURIComponent(curDom.data('value'))
      menuButton.updateFormat(d, "ct", fa);
    }
  },
  custom() {
    // 自定义
    const curDom = $('#fmtDateList').find('.curListItem')
    if (curDom) {
      let d = editor.deepCopyFlowData(Store.flowdata);//取数据
      const fa = decodeURIComponent(curDom.data('value'))
      menuButton.updateFormat(d, "ct", fa);
    }
  },
  special() {
    // 特殊
    const curDom = $('#fmtDateList').find('.curListItem')
    if (curDom) {
      let d = editor.deepCopyFlowData(Store.flowdata);//取数据
      const fa = decodeURIComponent(curDom.data('value'))
      menuButton.updateFormat(d, "ct", fa);
    }
  }


}

export default listConfirmFns